import {Component} from '@angular/core';
import {FormBuilder, FormGroup, Validators} from '@angular/forms';
import {ActivatedRouteSnapshot, RouterStateSnapshot} from '@angular/router';
import {MessageUtilService} from 'great-zorroutils';
import {Observable} from 'rxjs';

@Component({
  selector: 'app-form-form-leave',
  templateUrl: './form-leave.component.html',
})
export class FormFormLeaveComponent {

  formGrop: FormGroup;

  constructor(
    private fb: FormBuilder,
    private messageService: MessageUtilService,
  ) {
    this.formGrop = this.fb.group({
      userName: ['', [Validators.required]],
      email: ['', [Validators.email, Validators.required]],
      password: ['', [Validators.required]],
      confirm: ['', ],
      comment: ['', [Validators.required]]
    });
  }

  canDeactivate(
    component?: any,
    currentRoute?: ActivatedRouteSnapshot,
    currentState?: RouterStateSnapshot,
    nextState?: RouterStateSnapshot): Observable<boolean> | boolean {
    if (this.formGrop.dirty) {
      return this.messageService.confirm();
    } else {
      return true;
    }
  }

}
